package com.wkh.datastructure.stack;

import com.wkh.datastructure.queue.ArrayQueue;

//双栈模拟队列
public class SimulatedQueue {
    private ArrayStack<Integer> stack1 = new ArrayStack<>(100);
    private ArrayStack<Integer> stack2 = new ArrayStack<>(100);

    public void push(int x){
        stack2.push(x);
    }
    public int pop(){
        if (stack1.isEmpty()){
            while (!stack2.isEmpty()){
                stack1.push(stack2.pop());
            }
        }
        return stack1.pop();
    }
    public int peek(){
        if (stack1.isEmpty()){
            while (!stack2.isEmpty()){
                stack1.push(stack2.pop());
            }
        }
        return stack1.peek();
    }
    public boolean empty(){
        return stack1.isEmpty() && stack2.isEmpty();
    }
}
